/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: $ {USER}
 * Date: $ {YEAR}-$ {MONTH}一$ { DAY}
 * Time: ${ TIME}
 */

import java.util.Arrays;
import java.util.Scanner;

/**
 *
 */
public class Test {
    public static void rotate(int[] nums, int k) {
        if (nums.length < 2) {
            return;
        }
        // 旋转数组
        // 先整体旋转，再旋转前K这个，再旋转后K个
        int l = 0;
        int r = nums.length - 1;
        while (l < r) {
            int tmp = nums[l];
            nums[l] = nums[r];
            nums[r] = tmp;
            l++;
            r--;
        }
        // 判断k的大小，是k变成有效的次数
        while (k > nums.length) {
            k -= nums.length; // 等效于 k %= n
        }
        // 接下来的k是有效的次数，就可以开始旋转了
        // 旋转前K这个元素
        l = 0;
        r = k - 1;
        while (l < r) {
            int tmp = nums[l];
            nums[l] = nums[r];
            nums[r] = tmp;
            l++;
            r--;
        }
        //旋转后k个元素
        l = k;
        r = nums.length - 1;
        while (l < r) {
            int tmp = nums[l];
            nums[l] = nums[r];
            nums[r] = tmp;
            l++;
            r--;
        }
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4,5,6,7};
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        System.out.println("旋转"+k+"前："+ Arrays.toString(nums));
        rotate(nums, k);
        System.out.println("旋转"+k+"后："+ Arrays.toString(nums));
    }
}
